package com.demo.supplier.controller;

import com.demo.supplier.common.R;
import com.demo.supplier.constant.ApiConstants;
import com.demo.supplier.entity.LoginLog;
import com.demo.supplier.entity.OperationLog;
import com.demo.supplier.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 日志管理控制器
 * 
 * @author demo
 */
@Slf4j
@RestController
@RequestMapping("${api.prefix}" + ApiConstants.LOGS)
@Api(tags = "日志管理")
public class LogController {

    @Autowired
    private LogService logService;

    @GetMapping("/operation")
    @ApiOperation("操作日志分页查询")
    public R<Page<OperationLog>> pageOperationLogs(
            @ApiParam("当前页码") @RequestParam(defaultValue = "1") int page,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") int size,
            @ApiParam("搜索关键词") @RequestParam(required = false) String keyword) {
        
        Page<OperationLog> operationLogs = logService.pageOperationLogs(page, size, keyword);
        return R.success(operationLogs);
    }

    @GetMapping("/login")
    @ApiOperation("登录日志分页查询")
    public R<Page<LoginLog>> pageLoginLogs(
            @ApiParam("当前页码") @RequestParam(defaultValue = "1") int page,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") int size,
            @ApiParam("搜索关键词") @RequestParam(required = false) String keyword) {
        
        Page<LoginLog> loginLogs = logService.pageLoginLogs(page, size, keyword);
        return R.success(loginLogs);
    }
}